'use strict';

const Controller = require('egg').Controller;

/**
* @controller MenuController 注释必写，swagger-doc是根据这段注释来生成接口的 ）。
*/
class MenuController extends Controller {
//   async findListTree() {
//     /**
//     * @summary menulisttree
//     * @description menulisttree
//     * @router get /menulisttree
//     */
//     let result = await this.service.menu.findListTree()
//     this.ctx.body = {
//         msg:"",
//         data:result.data,
//         data:result.rows
//     }
//   }
  async findList() {
      const module_id = this.ctx.request.body.moduleID || 0;
      let result = await this.service.menu.findList(module_id)
      this.ctx.body = {
        data: result,
        msg: '',
        count: result.length,
      }
  }
  async create(){
    const params = this.ctx.request.body;
    await this.service.menu.create(params)
    this.ctx.body = {
        msg:"create successful"
    }
  }
  async edit(){
    const params = this.ctx.request.body
    await this.service.menu.edit(params)
    this.ctx.body = {
        msg:"edit successful"
    }
  }
  async delete(){
    const params = this.ctx.request.body
    await this.service.menu.delete(params)
    this.ctx.body = {
      msg:"delete successful"
    }
  }
  async showMenuTree(){
    const params = this.ctx.request.body.moduleID
    const result = await this.service.menu.findListTree();
    const treeData = await this.service.menu.recombinationMenuTree(result, params);
    this.ctx.body = {
      status: 0,
      treeData,
    };
  }
  async findById(){
      let params = this.ctx.request.body
      let result = await this.service.menu.findById(params)
      this.ctx.body = {
          status:0,
          data:result
      }
  }
}

module.exports = MenuController;
